package com.realtyManage.springboot.Controller;

import com.alibaba.fastjson.JSON;
import com.realtyManage.springboot.Config.AliMessage;
import com.realtyManage.springboot.Config.MyLog;
import com.realtyManage.springboot.Dao.CodeRepository;
import com.realtyManage.springboot.Model.Do.*;
import com.realtyManage.springboot.Model.Vo.*;
import com.realtyManage.springboot.Service.*;
import com.realtyManage.springboot.Utils.RedisService;
import com.realtyManage.springboot.Utils.SysExecRsUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * BackgroundManagementController
 *
 * @Author 杭州素色网络科技有限公司
 * @Date 2019/7/28
 * 后台管理Controller
 **/
@Controller
@ResponseBody
@RequestMapping("/management")
public class BackgroundManagementController {

    private static CodeRepository codeService;
    @Autowired
    protected BCryptPasswordEncoder bCryptPasswordEncoder;

    @Autowired
    private IHouseDetailService houseDetailService;

    @Autowired
    private IUserService userService;

    @Autowired
    private ICustomerService customerService;

    @Autowired
    private IAgreementService agreementService;

    @Autowired
    private IBannerService bannerService;

    @Autowired
    private IAnnouncementService announcementService;

    @Autowired
    private ICommentService commentService;

    @Autowired
    private IApplyInfoService applyInfoService;

    @Autowired
    private IShopService shopService;

    @Autowired
    private IIndexHotHouseService indexHotHouseService;

    @Autowired
    private IIndexService indexService;

    @Autowired
    private IArticleService articleService;

    @Autowired
    private IActiveService activeService;

    @Autowired
    private IHulkService hulkService;

    @Autowired
    private IHulkTypeService hulkTypeService;

    @Autowired
    private RedisService redisService;

    @Autowired
    private ISpecialOfferHouseService iSpecialOfferHouseService;

    @Autowired
    private IContactService contactService;

    @Autowired
    private IQuestionsAnswersService questionsAnswersService;

    @Autowired
    private ICustomerRegistrationService customerRegistrationService;

    @Autowired
    private IUserTaskService userTaskService;


    //------房源管理开始------

    /**
     * 获取房源参数
     * @param request
     * @getHouseParameter
     */
    @RequestMapping(value = "/getHouseParameter",method = RequestMethod.GET)
    private String getHouseParameter(HttpServletRequest request) {
        String type = request.getParameter("type");
        List<String> houseMapParameter = houseDetailService.getHouseParameter(type);
        return JSON.toJSONString(houseMapParameter);
    }

    /**
     * 获取房源
     * @param request
     * @returnshowHouseList
     */
    @RequestMapping(value = "/showHouseList")
    private String showHouseList(HouseEntity entity, HttpServletRequest request) {
        Page<HouseDetail> houseDetailList = houseDetailService.findPagedByWhereClause(entity);
        return JSON.toJSONString(houseDetailList);
    }

    /**
     * 新建楼盘
     * @param houseDetail
     * @param request
     * @return
     */
    @RequestMapping(value = "/saveHouseInfo",method = RequestMethod.POST)
    private String saveHouseInfo(HouseDetail houseDetail, HttpServletRequest request) {
        houseDetail.setIsShow(1);
        houseDetail.setAddTime(new Date());
        houseDetail.setAddUid(userService.findByTelePhone(request.getSession().getAttribute("user").toString()).getId());
        houseDetail.setAddUserName(userService.findByTelePhone(request.getSession().getAttribute("user").toString()).getName());
        return JSON.toJSONString(houseDetailService.saveHouseInfo(houseDetail));
    }

    @RequestMapping(value = "/updateHouseInfo",method = RequestMethod.POST)
    private String updateHouseInfo(@RequestBody HouseDetail houseDetail, HttpServletRequest request) {
        return JSON.toJSONString(houseDetailService.updateHouseInfo(houseDetail));
    }

    //------楼盘管理结束------

    //------平台管理员开始------
    @RequestMapping(value = "/saveUser",method = RequestMethod.POST)
    private String getHouseCustInfo(RegEntity entity, HttpServletRequest request) {
        if(userService.isExistPhone(entity.getUsername())==false){
            User user = new User();
            user.setTelephone(entity.getName());
            user.setPwd(bCryptPasswordEncoder.encode(entity.getPassword()));
           // user.setLevel(98);
            user.setStatus(1);
            user.setRegTime(new Date());
            if(userService.insert(user)!=null){
                return JSON.toJSONString("新增成功");
            }else{
                return JSON.toJSONString("新增失败");
            }
        }else{
            return JSON.toJSONString("该用户名已存在");
        }
    }
    //------平台管理员结束------

    //------用户管理开始------
    @RequestMapping(value = "/showUserList")
    private String showUserList(UserEntity entity, HttpServletRequest request) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if(entity.getUpName()!=null && entity.getUpName().toString()!=""){
            List<String> upIds = userService.findByNameLike(entity.getUpName());
            if(upIds.size()>0){
                entity.setUpIds(upIds);
            }
        }
        if(entity.getShopName()!=null && entity.getShopName().toString()!=""){
            List<String> shopIds = shopService.findByNameLike(entity.getShopName());
            if(shopIds.size()>0){
                entity.setShopIds(shopIds);
            }
        }
        if(entity.getManageHouseName()!=null && entity.getManageHouseName().toString()!=""){
            List<String> houseIds = houseDetailService.findByNameLike(entity.getManageHouseName());
            if(houseIds.size()>0){
                entity.setManageHouseIds(houseIds);
            }
        }
        Page<User> userPage = userService.findPagedByWhereClause(entity);
        List<UserEntity> list = new ArrayList<>();
        List<User> userList = userPage.getContent();
        for(User user : userList){
            if(user.getLevel() != 99){
                UserEntity userEntity = new UserEntity();
                userEntity.setUid(user.getId());
                userEntity.setName(user.getName());
                userEntity.setLevel(user.getLevel());
                userEntity.setPhone(user.getTelephone());
                userEntity.setPersonalId(user.getPersonalId());
                userEntity.setRegTime(sdf.format(user.getRegTime()));
                if(user.getConnShopId()!=null && user.getConnShopId().toString()!=""){//门店负责人、门店经纪人所属门店
                    userEntity.setShopId(user.getConnShopId());
                    userEntity.setShopName(shopService.getOne(user.getConnShopId()).getName());
                }
               /* if(user.getManageHouseId()!=null && user.getManageHouseId().toString()!=""){//楼盘管理员管理楼盘
                    userEntity.setManageHouseName(indexService.getHouseDetail(user.getManageHouseId()).getName());
                }*/
                if(user.getUpId()!=null && user.getUpId().toString() != ""){//独立经纪人上线名称
                    userEntity.setUpName(userService.findById(user.getUpId()).getName());
                }
                userEntity.setApplyCustNum(customerService.countByConnUserIdAndState(user.getId(),1));
                userEntity.setDealCustNum(customerService.countByConnUserIdAndState(user.getId(),7));

                userEntity.setSettledCharge(0.00);
                userEntity.setUnsettledCharge(0.00);
                list.add(userEntity);
            }
        }
        HashMap<String,Object> map = new HashMap<>();
        map.put("content",list);
        map.put("totalElements",userPage.getTotalElements());
        return JSON.toJSONString(map);
    }

    @RequestMapping(value = "/saveUserInfo",method = RequestMethod.POST)
    private String saveUserInfo(User user, HttpServletRequest request) {
        user.setRegTime(new Date());
        user.setJoinTime(new Date());
        return JSON.toJSONString(userService.insert(user));
    }

    @RequestMapping(value = "/updateUserInfo",method = RequestMethod.POST)
    private Boolean updateUserInfo(UserEntity entity, HttpServletRequest request) {
        User user = userService.findById(entity.getUid());
        if(entity.getManageHouseId()!=null&&entity.getManageHouseId().toString()!=""){
            user.setManageHouseId(entity.getManageHouseId());
        }
        if(entity.getPassword()!=null && (entity.getLevel()==97 || entity.getLevel()==98 || entity.getLevel()==1)){
            user.setPwd(bCryptPasswordEncoder.encode(entity.getPassword()));
        }
        user.setLevel(entity.getLevel());
        if(userService.updateUserInfo(user)!=null){
            return true;
        }else{
            return false;
        }
    }

    //门店负责人变更流程
    @ResponseBody
    @RequestMapping("/powerChange")
    public String shopManagerChange(PowerMoveEntity entity, HttpServletRequest request) {
        int operateCode = entity.getOperateCode();
        int code = -1;
        switch (operateCode){
            case 1://门店负责人转移
                code = userService.changeShopManager(entity.getConnShopId(),entity.getSourceUid());
                break;
            case 2://楼盘管理员转移
                break;
            case 3://平台管理员转移

                break;
        }

        entity.setInfoCode(code);
        entity.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return JSON.toJSONString(entity);
    }
    //------用户管理结束------


    //------报备客户管理开始------
    @RequestMapping(value = "/showCustomerList")
    private String showCustomerList(CustomerEntity entity, HttpServletRequest request) {
        HashMap map = new HashMap();
        if(entity.getBusinessManagerName()!=null && entity.getBusinessManagerName().toString()!=""){
            List<String> bussinessManagerIds = userService.findByNameLike(entity.getBusinessManagerName());
            if(bussinessManagerIds.size()>0){
                entity.setBusinessManagerIds(bussinessManagerIds);
            }
        }
        if(entity.getHouseName()!=null && entity.getHouseName().toString()!=""){
            List<String> houseIds = houseDetailService.findByNameLike(entity.getHouseName());
            if(houseIds.size()>0){
                entity.setHouseIds(houseIds);
            }
        }
        return JSON.toJSONString(customerService.findPagedByWhereClause(entity));
    }

    @RequestMapping(value = "/updateCustomerStatus",method = RequestMethod.POST)
    private String updateCustomerStatus(CustFlowEntity entity, HttpServletRequest request) {
        return JSON.toJSONString(customerService.updateCustomerInfo(entity,request));
    }
    //------报备客户管理结束------

    //------其他设置开始------
    @RequestMapping(value = "/updateAgreement",method = RequestMethod.POST)
    private String updateAgreement(Agreement entity, HttpServletRequest request) {
        RegEntity regInfo = new RegEntity();
        if(agreementService.updateContent(entity)){
            regInfo.setInfoCode(1);
            regInfo.setInfoText(SysExecRsUtil.getMsgFromCode(1));
        }else{
            regInfo.setInfoCode(-1);
            regInfo.setInfoText(SysExecRsUtil.getMsgFromCode(-1));
        }
        return JSON.toJSONString(regInfo);
    }

    @RequestMapping(value = "/saveBannerInfo",method = RequestMethod.POST)
    private String saveBannerInfo(Banner banner, HttpServletRequest request) {
        if(banner.getId() != null && banner.getId().toString() != ""){
            Banner bannerOld = bannerService.getOne(banner.getId());
            if(banner.getState() != null && banner.getState().toString() != null){//删除
                bannerOld.setState(banner.getState());
                return JSON.toJSONString(bannerService.insert(bannerOld));
            }else{//更新
                Banner bannerNew = new Banner();
                bannerNew.setId(bannerOld.getId());
                bannerNew.setConnHouseId(banner.getConnHouseId());
                bannerNew.setOutLink(banner.getOutLink());
                bannerNew.setPic(banner.getPic());
                bannerNew.setHouseName(banner.getHouseName());
                bannerNew.setType(banner.getType());
                bannerNew.setArea(banner.getArea());
                bannerNew.setState(1);
                return JSON.toJSONString(bannerService.insert(bannerNew));
            }
        }else{//新增
            banner.setState(1);
            return JSON.toJSONString(bannerService.insert(banner));
        }
    }

    @RequestMapping(value = "/saveAnnouncementInfo",method = RequestMethod.POST)
    private String saveAnnouncementInfo(HttpServletRequest request) {
        Announcement announcement = new Announcement();
        if(request.getParameter("id")!=null && request.getParameter("id").toString()!=""){
            Announcement announcementOld = announcementService.getOne(Integer.parseInt(request.getParameter("id")));
            if(request.getParameter("state")!=null && request.getParameter("state").toString()!=""){//删除
                announcementOld.setState(Integer.parseInt(request.getParameter("state")));
                return JSON.toJSONString(announcementService.insert(announcementOld));
            }else{//更新
                announcementOld.setTitle(request.getParameter("title"));
                return JSON.toJSONString(announcementService.insert(announcementOld));
            }
        }else{//新增
            announcement.setTitle(request.getParameter("title").toString());
            announcement.setState(1);
            announcement.setType(1);
            announcement.setTime(new Date());
            return JSON.toJSONString(announcementService.insert(announcement));
        }

    }

    @RequestMapping(value = "/getHotHouseList",method = RequestMethod.GET)
    private HashMap<String,List<HouseDetail>> saveHotHouse(HttpServletRequest request) {
        HashMap<String,List<HouseDetail>> map = new HashMap<>();
        List<IndexHotHouse> indexHotHouseList = indexHotHouseService.findAll();
        for(IndexHotHouse indexHotHouse : indexHotHouseList){
            List<HouseDetail> list = new ArrayList<>();
            if(!StringUtils.deleteWhitespace(indexHotHouse.getHotHouse()).equals("")) {
                String[] houseIds = indexHotHouse.getHotHouse().split(",");
                for (String hid : houseIds) {
                    list.add(indexService.getHouseDetail(Integer.parseInt(hid)));
                }
            }
            map.put(indexHotHouse.getArea(),list);
        }
        return map;
    }

    //新增热门楼盘
    @RequestMapping(value = "/saveHotHouse",method = RequestMethod.POST)
    private boolean saveHotHouse(@RequestParam("hotHouseIds") String hotHouseIds,@RequestParam("area") String area, HttpServletRequest request) {
        IndexHotHouse indexHotHouse = new IndexHotHouse();
        List<IndexHotHouse> indexHotHouseList = indexHotHouseService.findByArea(area);
        if(indexHotHouseList.size()==1){
            indexHotHouse = indexHotHouseService.findByArea(area).get(0);
        }
        indexHotHouse.setHotHouse(hotHouseIds);
        indexHotHouse.setArea(area);
        if (indexHotHouseService.save(indexHotHouse)){
            redisService.remove(area+"hotHouse");
            return true;

        }else {
            return false;
        }
    }

    //------其他设置结束------

    //------活动相关开始------

    //统计单个活动参与人数
    @RequestMapping(value = "/censusActiveInfo",method = RequestMethod.GET)
    private String censusActiveInfo(@RequestParam("activeId") Integer activeId,HttpServletRequest request) {
        Map<String,Object> map = new HashMap<>();
        List<Active> activeList = activeService.censusActiveInfo(activeId);
        List<User> userList = new ArrayList<>();
        for(Active active : activeList){
            userList.add(userService.findById(active.getUid()));
        }
        return JSON.toJSONString(userList);
    }

    //新增文章或活动
    @RequestMapping(value = "/saveArticle",method = RequestMethod.POST)
    private String saveArticle(Article article, HttpServletRequest request) {
        BaseEntity entity = new BaseEntity();
            int code = 0;
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            article.setAddTime(new Date());
            article.setShowTime(article.getShowTime()==""?sdf.format(new Date()):article.getShowTime());
            article.setState(1);
            if(articleService.save(article) > 0){
                code = 1;
            }else{
                code = -1;
            }

        entity.setInfoCode(code);
        entity.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return JSON.toJSONString(entity);
    }

    //更新、删除文章或活动
    @RequestMapping(value = "/updateArticle",method = RequestMethod.POST)
    private Boolean updateArticle(Article article,HttpServletRequest request) {
        article.setAddTime(new Date());
        if(articleService.update(article)==1){
            return true;
        }else{
            return false;
        }
    }

    //活动奖励结算
    @RequestMapping(value = "/activeSettled",method = RequestMethod.POST)
    private String activeSettled(HttpServletRequest request) {
        //TODO 活动奖励结算

        return null;
    }
    //------活动相关结束------

    //------获客海报开始------
    //新增、更新海报
    @RequestMapping(value = "/updateHulk",method = RequestMethod.POST)
    private Boolean updateHulk(Hulk hulk,HttpServletRequest request) {
        if(hulk.getId() == null){//批量新增
            String[] images = hulk.getImages().split(",");
            int i = 0;
            for(String image : images){
                hulk.setImage(image);
                hulk.setType(hulk.getType());
                if(hulkService.save(hulk)!=null){
                    i++;
                }
            }
            if(i==images.length){
                return true;
            }else {
                return false;
            }
        }else{
            String img = hulk.getImage();
            hulk = hulkService.getOne(hulk.getId());
            hulk.setImage(img);
            if(hulkService.save(hulk)!=null){
                return true;
            }else{
                return false;
            }
        }
    }

    //删除海报
    @RequestMapping(value = "/deleteHulk",method = RequestMethod.POST)
    private Boolean deleteHulk(Hulk hulk,HttpServletRequest request) {
        hulkService.delete(hulk.getId());
        return true;
    }

    //新增、更新海报分类
    @RequestMapping(value = "/updateHulkType",method = RequestMethod.POST)
    private String updateHulk(HulkType hulkType, HttpServletRequest request) {
        if(hulkTypeService.save(hulkType)!=null){
            hulkType.setInfoCode(1);
            hulkType.setInfoText(SysExecRsUtil.getMsgFromCode(1));
        }else{
            hulkType.setInfoCode(-1);
            hulkType.setInfoText(SysExecRsUtil.getMsgFromCode(-1));
        }
        return JSON.toJSONString(hulkType);
    }

    //删除海报分类
    @RequestMapping(value = "/deleteHulkType",method = RequestMethod.POST)
    private Boolean deleteHulk(HulkType hulkType,HttpServletRequest request) {
        hulkTypeService.delete(hulkType.getId());
        return true;
    }

    //------获客海报结束------

    /**
     * 设置周边城市主推
     * @param request
     * @return
     */
    @RequestMapping(value = "/setPeriphery",method = RequestMethod.POST)
    private String setPeriphery(PeripheryEntity pe, HttpServletRequest request) {
        String id = pe.getHouseId();
        String cityId = null;
        if (pe.getArea1().length() > 0){
             cityId = pe.getArea1()+";";
        }
        if (pe.getArea2().length() > 0){
            cityId += pe.getArea2()+";";
        }
        if(pe.getArea3().length() > 0){
            cityId += pe.getArea3()+";";
        }
        if (pe.getArea4().length() > 0) {
            cityId += pe.getArea4()+";";
        }
        if (pe.getArea5().length() > 0) {
            cityId += pe.getArea5()+";";
        }
        if (pe.getArea6().length() > 0) {
            cityId += pe.getArea6()+";";
        }
        if (pe.getArea7().length() > 0) {
            cityId += pe.getArea7()+";";
        }
        if (pe.getArea8().length() > 0) {
            cityId += pe.getArea8()+";";
        }
        if (pe.getArea9().length() > 0) {
            cityId += pe.getArea9()+";";
        }
        if (pe.getArea10().length() > 0) {
            cityId += pe.getArea10()+";";
        }
        String cd = cityId.substring(0,cityId.length()-1).replace(",","");
        RegEntity regInfo = new RegEntity();
        int count = userService.setPeriphery(cd,id);
        if (count > 0){
            regInfo.setInfoCode(1);
            regInfo.setInfoText(SysExecRsUtil.getMsgFromCode(1));
        }else{
            regInfo.setInfoCode(-1);
            regInfo.setInfoText(SysExecRsUtil.getMsgFromCode(-1));
        }
        return JSON.toJSONString(regInfo);
    }

    /**
     *  返现数据（周边城市code）
     * @param houseId
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getPeriphery",method = RequestMethod.GET)
    public String getPeriphery(@RequestParam String houseId,HttpServletRequest request) {
        List list = new ArrayList<>();
        //获取楼盘信息
        String houseDetailsList = indexHotHouseService.findHouseId(houseId);
        if(houseDetailsList!=null && houseDetailsList.length() > 0){
            String[] houseIds = houseDetailsList.split(";");
                for (String hids : houseIds) {
                    String hid = hids.substring(0,6)+","+hids.substring(6,12);
                    list.add(hid);
                }
            return JSON.toJSONString(list);
        }else{
            BaseEntity baseEntity = new BaseEntity();
            baseEntity.setInfoCode(-1);
            baseEntity.setInfoText(SysExecRsUtil.getMsgFromCode(-1));
            return JSON.toJSONString(baseEntity);
        }
    }


    /**
     * 获取特价房
     * @param hid
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getTjHouse",method = RequestMethod.GET)
    public String getTjHouse(@RequestParam String hid,HttpServletRequest request) {
        List<SpecialOfferHouse> list = iSpecialOfferHouseService.getTjHouse(hid);
        if(list!=null && list.size() > 0){
            return JSON.toJSONString(list);
        }else{
            BaseEntity baseEntity = new BaseEntity();
            baseEntity.setInfoCode(-1);
            baseEntity.setInfoText(SysExecRsUtil.getMsgFromCode(-1));
            return JSON.toJSONString(baseEntity);
        }
    }

    /**
     * 新增特价房
  * @param specialOfferHouse
     * @param request
     * @return
     */
    @RequestMapping(value = "/saveSpecialOfferHouse",method = RequestMethod.POST)
    private String saveSpecialOfferHouse(SpecialOfferHouse specialOfferHouse,HttpServletRequest request) {
        BaseEntity entity = new BaseEntity();
        int code = 0;
        //循环插入数据
        if(!specialOfferHouse.getRelevanceHouseId().equals("")){
            //specialOfferHouse.setTime(new Date());
            specialOfferHouse.setZt(0);
            specialOfferHouse.setIsShow(0);
            if (iSpecialOfferHouseService.save(specialOfferHouse) != null){
                code = 1;
            }else{
                code  = -1;
            }
        }
        entity.setInfoCode(code);
        entity.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return JSON.toJSONString(entity);
    }


    /**
     * 删除特价房
     * @param specialOfferHouse
     * @param request
     * @return
     */
    @RequestMapping(value = "/deleteSpecialOfferHouse",method = RequestMethod.POST)
    private String deleteSpecialOfferHouse(SpecialOfferHouse specialOfferHouse,HttpServletRequest request) {
        BaseEntity entity = new BaseEntity();
        int code = 0;
        //循环插入数据
        if(!specialOfferHouse.getId().equals("")){
            try {
                iSpecialOfferHouseService.delete(specialOfferHouse);
                code = 1;
            }catch(Exception e) {
                code = -1;
            }
        }
        entity.setInfoCode(code);
        entity.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return JSON.toJSONString(entity);
    }

    /**
     * 根据id查询特价房
     * @param id
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/findSpecialOfferHouseById",method = RequestMethod.GET)
    private String  findSpecialOfferHouseById(@RequestParam String id,HttpServletRequest request){
        List<SpecialOfferHouse> list = new ArrayList<SpecialOfferHouse>();
        if (!id.equals("")){
            synchronized (this) {
                list = iSpecialOfferHouseService.findSpecialOfferHouseById(id);
                if (list.get(0).getZt() == 1) {
                    BaseEntity entity = new BaseEntity();
                    entity.setInfoCode(-4397);
                    entity.setInfoText(SysExecRsUtil.getMsgFromCode(-4397));
                    return JSON.toJSONString(entity);
                }
                //开始更改状态1 为支付中或者被抢购 15分钟
                iSpecialOfferHouseService.updateZfTasks(Integer.valueOf(id));
            }
        }else {
            BaseEntity entity = new BaseEntity();
            entity.setInfoCode(-1);
            entity.setInfoText(SysExecRsUtil.getMsgFromCode(-1));
            return JSON.toJSONString(entity);
        }
        return JSON.toJSONString(list);
    }

    /**
     * 修改特价房
     * @param specialOfferHouse
     * @param request
     * @return
     */
    @RequestMapping(value = "/updateSpecialOfferHouseById",method = RequestMethod.POST)
    private  String updateSpecialOfferHouseById(SpecialOfferHouse specialOfferHouse,HttpServletRequest request){
        Integer code = 1;
        if (!specialOfferHouse.getId().equals("")){
            try {
                iSpecialOfferHouseService.updateSpecialOfferHouseById(specialOfferHouse);
                code = 1;
            }catch (Exception e){
                code = -1;
            }
        }
        BaseEntity entity = new BaseEntity();
        entity.setInfoCode(code);
        entity.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return JSON.toJSONString(entity);
    }


    /**
     * 新增联系我们
     * @param contact
     * @param request
     * @return
     */
    @RequestMapping(value = "/saveContact",method = RequestMethod.POST)
    private String saveContact(Contact contact,HttpServletRequest request) {
        String telephone = "18868789355";
        contact.setTime(new Date());
        if(!contact.getName().equals("")){
            try {
                Integer value = contactService.insert(contact).getId();
                if (value != null || value != ' '){
                    String rs = AliMessage.sendMessage(6, "",telephone);
                    if (rs != null && rs.equals("OK")) {
                        System.out.println("短信发送成功");
                    } else {
                        System.out.println("短信发送失败");
                    }
                 }
                return JSON.toJSONString("新增成功");
            }catch (Exception e){
                return JSON.toJSONString("新增失败");
            }
        }else{
            return JSON.toJSONString("新增失败");
        }

    }


    /**
     *  导入问题
     * @param request
     * @return
     */
    @RequestMapping(value = "/saveQuestionsAnswers",method = RequestMethod.POST)
    @ResponseBody
    private String saveQuestionsAnswers(HttpServletRequest request) {
        //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String userValue =  request.getParameter("questionsAnswers");
        String jsonStr = "["+userValue+"]";   //因前端没有做包裹处理，故在后台做包裹处理
        JSONArray jsonArray = JSONArray.fromObject(jsonStr);
        QuestionsAnswers qa = new QuestionsAnswers();
        try {
            for(int i=0;i<jsonArray.size(); i++) {
                JSONObject jsonJ = jsonArray.getJSONObject(i);
                qa.setHouseId(Integer.valueOf(jsonJ.getString("houseId")));
                qa.setUserId(userService.findByTelePhone(request.getSession().getAttribute("user").toString()).getId());
                qa.setUserName(userService.findByTelePhone(request.getSession().getAttribute("user").toString()).getName());
                qa.setQuestions(jsonJ.getString("questions"));
                qa.setAnswers(jsonJ.getString("answers"));
                qa.setTime(new Date());
                qa.setIsShow(0);
                questionsAnswersService.save(qa);
            }
        }catch (Exception e){
            return "上传失败！";
        }
        return "上传成功！";
    }

    /**
     * 导入楼盘详情列表
     * @param request
     * @return
     */
    @RequestMapping(value = "/saveHouseDetailList",method = RequestMethod.POST)
    @ResponseBody
    private String saveHouseDetailList(HttpServletRequest request) {
        String houseValue =  request.getParameter("house");
        String jsonStr = "["+houseValue+"]";   //因前端没有做包裹处理，故在后台做包裹处理
        JSONArray jsonArray = JSONArray.fromObject(jsonStr);

        for(int i=0;i<jsonArray.size(); i++) {
            HouseDetail hd = new HouseDetail();
            JSONObject jsonJ = jsonArray.getJSONObject(i);

            hd.setAddUid(userService.findByTelePhone(request.getSession().getAttribute("user").toString()).getId());
            hd.setAddUserName(userService.findByTelePhone(request.getSession().getAttribute("user").toString()).getName());
            hd.setIsShow(1);
            hd.setAddTime(new Date());
            houseDetailService.saveHouseInfo(hd);
        }
        return "200";
    }


    /**
     * 获取答客百问
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/findQuestionsAnswers",method = RequestMethod.GET)
    private String  findQuestionsAnswers(HttpServletRequest request){
        String center = request.getParameter("center");
        return JSON.toJSONString(questionsAnswersService.findQuestionsAnswers(center));
    }

    /**
     * 删除百问百答
     * @param qa
     * @param request
     * @return
     */
    @RequestMapping(value = "/deleteQuestions",method = RequestMethod.POST)
    private String deleteQuestions(QuestionsAnswers qa, HttpServletRequest request) {
        BaseEntity be = new BaseEntity();
        Integer code = -1;
        if (questionsAnswersService.deleteQuestions(qa.getId()) > 0){
            code = 1;
        }
        be.setInfoCode(code);
        be.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return JSON.toJSONString(be);
    }

    /**
     *  新增问题
     * @param qa
     * @param request
     * @return
     */
    @RequestMapping(value = "/saveQuestions",method = RequestMethod.POST)
    private String saveQuestions(QuestionsAnswers qa, HttpServletRequest request) {
        BaseEntity be = new BaseEntity();
        int code = 0;
        if (qa.getQuestions() != null){
            qa.setIsShow(0);
            qa.setTime(new Date());
            qa.setUserId(userService.findByTelePhone(request.getSession().getAttribute("user").toString()).getId());
            qa.setUserName(userService.findByTelePhone(request.getSession().getAttribute("user").toString()).getName());
            if (questionsAnswersService.save(qa) != null){
                code = 1;
            }else{
                code = -1;
            }
        }else{
            code = -1;
        }
        be.setInfoCode(code);
        be.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return JSON.toJSONString(be);
    }

    /**
     * 反馈问题列表
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/findQuestionsList",method = RequestMethod.GET)
    private String  findQuestionsList(HttpServletRequest request){
        List<QuestionsAnswers> list  = questionsAnswersService.findQuestionsList();
        return JSON.toJSONString(list);
    }

    /**
     * 回复反馈问题
     * @param qa
     * @param request
     * @return
     */
    @RequestMapping(value = "/setAnswers",method = RequestMethod.POST)
    private String setAnswers(QuestionsAnswers qa, HttpServletRequest request) {
        BaseEntity be = new BaseEntity();
        int code = 0;
        if (qa.getAnswers() != null){
            if (questionsAnswersService.setAnswers(qa) > 0){
                code = 1;
            }else{
                code = -1;
            }
        }else{
            code = -1;
        }
        be.setInfoCode(code);
        be.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return JSON.toJSONString(be);
    }

    /**
     * 按id查询信息
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/findQuestionsById",method = RequestMethod.GET)
    private String  findQuestionsById(HttpServletRequest request){
        Integer id = Integer.valueOf(request.getParameter("id"));
        List<QuestionsAnswers> list  = questionsAnswersService.findQuestionsById(id);
        return JSON.toJSONString(list);
    }

    /***************************************************************************房源管理*******************************************************/
    /*房源批量上传*/

    /*房源批量删除*/
    @ResponseBody
    @RequestMapping(value = "/deleteHouse",method = RequestMethod.POST)
    private String deleteHouse(HttpServletRequest request, HttpServletResponse response){
        Integer code = 1;
        BaseEntity baseEntity = new BaseEntity();
        String ids = request.getParameter("ids");
        if (houseDetailService.deleteHouse(ids) > 0){
            code = 1;
        }else{
            code = -1;
        }
        baseEntity.setInfoCode(code);
        baseEntity.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return JSON.toJSONString(baseEntity);
    }

    /*房源下载*/

    /*房源设为特价房*/
    @ResponseBody
    @RequestMapping(value = "/updateSuperHouse",method = RequestMethod.POST)
    private String updateSuperHouse(HouseDetail houseDetail,HttpServletRequest request){
        Integer code = 1;
        BaseEntity baseEntity =new BaseEntity();
        if (houseDetailService.updateHouseInfo(houseDetail)){
            code = 1;
        }else{
            code = -1;
        }
        baseEntity.setInfoCode(code);
        baseEntity.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return JSON.toJSONString(baseEntity);
    }


    /***************************************************************************客户统计*******************************************************/
    //验证是否初次用户
    @ResponseBody
    @RequestMapping(value = "/findFirst",method = RequestMethod.GET)
    private int findFirst(HttpServletRequest request){
        BaseEntity baseEntity =new BaseEntity();
        String phone = request.getParameter("phone");
        String id = userService.findByTelePhone(request.getSession().getAttribute("user").toString()).getId().toString();
        return customerRegistrationService.findFirst(phone,id);      //0通过  1有重复置业顾问
    }

    /*新增客户来访*/
    @ResponseBody
    @RequestMapping(value = "/addComoCustom",method = RequestMethod.POST)
    private String addComeCustom(CustomerRegistration customerRegistration,HttpServletRequest request){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Integer code = 1;
        Integer id = null;
        BaseEntity baseEntity =new BaseEntity();
        Date date = null;
        //判断是否为首次来访
        CustomerRegistration  isFirst= customerRegistrationService.findByPhone(customerRegistration.getPhone());
        Integer cid = userService.findByTelePhone(request.getSession().getAttribute("user").toString()).getId();
        if (isFirst == null){
            if (customerRegistration.getId() == null || customerRegistration.getId() == ' '){
                customerRegistration.setReceptionId(userService.findByTelePhone(request.getSession().getAttribute("user").toString()).getId());
                customerRegistration.setReceptionName(userService.findByTelePhone(request.getSession().getAttribute("user").toString()).getName());
                //判断来访和来电
                if (customerRegistration.getDescribe() != null){
                    customerRegistration.setVisit(1);
                }
                if (customerRegistration.getIncomingCalls() != null){
                    customerRegistration.setIncomingCall(1);
                }
                if (customerRegistration.getCustomerType() == null){
                    customerRegistration.setCustomerType("继续跟踪");
                }else if (customerRegistration.getCustomerType().equals("已全款")){
                    customerRegistration.setDealPaymentType("全款/放款");
                }
                customerRegistration.setIsShow(0);
                customerRegistration.setEffective(0);
                customerRegistration.setIdentify(0);
                customerRegistration.setMoneyBack("0");
                customerRegistration.setTotalContract("0");
                customerRegistration.setLargeSum(0);
                customerRegistration.setDownPaymentsMoney("0");
                customerRegistration.setExpandCustomer(0);
                customerRegistration.setIncomingCall(0);
                customerRegistration.setInvitation(0);
                customerRegistration.setVirtualNumber(customerRegistration.getPhone().substring(0,3)+customerRegistration.getPhone().substring(7,11)); //虚拟号码
                //判断客户来源
                if (customerRegistration.getCustomerSource().equals("来访")){
                    customerRegistration.setVisit(1);
                }else if (customerRegistration.getCustomerSource().equals("外拓")){
                    customerRegistration.setVisit(1);
                }else if (customerRegistration.getCustomerSource().equals("渠道")){
                    customerRegistration.setVisit(1);
                }else if (customerRegistration.getCustomerSource().equals("介绍")){
                    customerRegistration.setVisit(1);
                }else{
                    customerRegistration.setVisit(0);
                }
                try {
                    date = sdf.parse(sdf.format(new Date()));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                customerRegistration.setComeTime(date);
                id = customerRegistrationService.saveCustomerRegistrationInfo(customerRegistration);
            }
        }else{
            //判断是否为同一置业顾问信息
            if (isFirst.getReceptionId() == cid){
                code = -4;
                baseEntity.setInfoCode(code);
                baseEntity.setInfoText("此号码用户已被"+isFirst.getReceptionName()+"录入！");
                return  JSON.toJSONString(baseEntity);
            }
            //跟新客户来访最新时间
            customerRegistrationService.updateCustomerTime(customerRegistration.getPhone());
        }
        //添加来访记录
        CustomerRecord customerRecord= new CustomerRecord();
        if (customerRegistration.getCustomerSource().equals("来电")){
            customerRecord.setType(1);
            if (customerRegistration.getIncomingCalls() == null ){
                customerRegistration.setIncomingCalls("无");
            }
            customerRecord.setContent(customerRegistration.getIncomingCalls());
        }else{
            customerRecord.setType(0);
            if (customerRegistration.getDescribe() == null ){
                customerRegistration.setDescribe("无");
            }
            customerRecord.setContent(customerRegistration.getDescribe());
        }

        customerRecord.setInfoTime(new Date());
        customerRecord.setUid(userService.findByTelePhone(request.getSession().getAttribute("user").toString()).getId());
        if (id == null){
            if (customerRegistration.getId() == null){
                customerRecord.setCustomId(Integer.valueOf(customerRegistrationService.findByPhone(customerRegistration.getPhone()).getId()));
            }else{
                customerRecord.setCustomId(customerRegistration.getId());
            }
        }else{
            customerRecord.setCustomId(id);
        }
        if (customerService.addCustomerRecord(customerRecord) > 0){
            code = 1;
        }else {
            code = -1;
        }
        baseEntity.setInfoCode(code);
        baseEntity.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return  JSON.toJSONString(baseEntity);
    }

    /**
     * 增加客户来访信息记录
     * @param customerRecord
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/addCustomerRecord",method = RequestMethod.POST)
    private String addCustomerRecord(CustomerRecord customerRecord,HttpServletRequest request){
        Integer code = -1;
        customerRecord.setInfoTime(new Date());
        customerRecord.setUid(userService.findByTelePhone(request.getSession().getAttribute("user").toString()).getId());
        customerRecord.setType(0);
        if (customerService.addCustomerRecord(customerRecord) > 0){
            code = 1;
        }
        BaseEntity baseEntity =new BaseEntity();
        baseEntity.setInfoCode(code);
        baseEntity.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return  JSON.toJSONString(baseEntity);
    }

    /**
     * 修改客户信息
     * @param customerRegistration
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/updateComoCustom",method = RequestMethod.POST)
    private String updateComoCustom(CustomerRegistration customerRegistration,HttpServletRequest request){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Integer code = -1;
        if (customerRegistration.getPhone() != null){
            customerRegistration.setVirtualNumber(customerRegistration.getPhone().substring(0,3)+customerRegistration.getPhone().substring(7,11));
        }
        if (customerRegistrationService.updateComoCustom(customerRegistration) > 0){
            code = 1;
        }
        BaseEntity baseEntity =new BaseEntity();
        baseEntity.setInfoCode(code);
        baseEntity.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return  JSON.toJSONString(baseEntity);
    }

    /*查询来访客户*/
    @ResponseBody
    @RequestMapping(value = "/queryCustom",method = RequestMethod.GET)
    private String queryCustom(CustomReEntity customReEntity,HttpServletRequest request){
        //customReEntity.setUserId(userService.findByTelePhone(request.getSession().getAttribute("user").toString()).getId().toString());
        //customReEntity.setUserId("160");
        Page<CustomerRegistration> list = customerRegistrationService.findPagedByWhereClause(customReEntity);
        return JSON.toJSONString(list);
    }

    /*客户统计*/
    @ResponseBody
    @RequestMapping(value = "/queryCountCusetom",method = RequestMethod.GET)
    private String queryCountCustom(CustomReEntity customReEntity,HttpServletRequest request){
        String year = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        SimpleDateFormat s = new SimpleDateFormat("yyyy");
        if (customReEntity.getType() != null && customReEntity.getType() != ""){
            if (customReEntity.getType().equals("1")){
                year = sdf.format(new Date());
            }else if (customReEntity.getType().equals("2")){
                year = s.format(new Date());
            }
        }
        CustomReEntity ce = customerRegistrationService.queryCountCustom(year);
        return  JSON.toJSONString(ce);
    }

    /**
     * 获取销售人员列表
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/querySalesperson",method = RequestMethod.GET)
    private String querySalesperson(HttpServletRequest request){
        List cr = customerRegistrationService.querySalesperson();
        return  JSON.toJSONString(cr);
    }

    /**
     * 查询特价房
     * @param request
     * @return
     * @throws ParseException
     */
    @ResponseBody
    @RequestMapping(value = "/querySpecial",method = RequestMethod.GET)
    private String querySpecial(HttpServletRequest request) throws ParseException {
        List<HouseDetail> cr = houseDetailService.querySpecial();
        return  JSON.toJSONString(cr);
    }

    @ResponseBody
    @RequestMapping(value = "/findPagedByWhereClause",method = RequestMethod.GET)
    private String findPagedByWhereClause(CommentEntity commentEntity,HttpServletRequest request) throws ParseException {
        return  JSON.toJSONString(commentService.findPagedByWhereClause(commentEntity));
    }

    /**
     * 查询待审核
     * @param commentEntity
     * @param request
     * @return
     * @throws ParseException
     */
    @ResponseBody
    @RequestMapping(value = "/findUnaudited",method = RequestMethod.GET)
    private String findUnaudited(CommentEntity commentEntity,HttpServletRequest request) throws ParseException {
        return  JSON.toJSONString(commentService.findUnaudited(commentEntity));
    }

    /**
     * 审核评论
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/approvalComment",method = RequestMethod.POST)
    private String addComment(HttpServletRequest request){
        Integer code = -1;
        String id = request.getParameter("id");
        BaseEntity baseEntity =new BaseEntity();
        if (commentService.approvalComment(id) > 0){
            code = 1;
        }
        baseEntity.setInfoCode(code);
        baseEntity.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return  JSON.toJSONString(baseEntity);
    }

    /**
     * 新增评论
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/addComment",method = RequestMethod.POST)
    private String addComment(Comment comment,HttpServletRequest request){
        Integer code = -1;
        Integer id = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        comment.setCommentTime(sdf.format(new Date()));
        BaseEntity baseEntity =new BaseEntity();
        comment.setType("0");
        if (commentService.saveCommentInfo(comment) > 0){
            code = 1;
        }
        baseEntity.setInfoCode(code);
        baseEntity.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return  JSON.toJSONString(baseEntity);
    }

    /**
     * 查询评论详情
     * @param request
     * @return
     * @throws ParseException
     */
    @ResponseBody
    @RequestMapping(value = "/findCommentById",method = RequestMethod.GET)
    private String findCommentById(HttpServletRequest request) throws ParseException {
        String cid = request.getParameter("cid");
        return  JSON.toJSONString(commentService.findCommentById(Integer.valueOf(cid)));
    }



    /**
     * 删除评论
     * @param request
     * @return
     * @throws ParseException
     */
    @ResponseBody
    @RequestMapping(value = "/deleteComment",method = RequestMethod.POST)
    private String deleteComment(HttpServletRequest request) {
        Integer code = -1;
        BaseEntity baseEntity =new BaseEntity();
        String ids = request.getParameter("ids");
        if(commentService.deleteComment(ids) > 0){
            code = 1;
        }
        baseEntity.setInfoCode(code);
        baseEntity.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return  JSON.toJSONString(baseEntity);
    }


    //导入价格表
    @ResponseBody
    @RequestMapping(value = "/importPriceList",method = RequestMethod.POST)
    private String importPriceList(@RequestParam("file") MultipartFile uploadFile,HttpServletRequest request) {
        if (uploadFile == null) {
            //判断文件大小
            return "上传文件为空文档";
        }
        //JSONArray jsonArray = JSONArray.fromObject(fileList);
        Integer code = 1;
        BaseEntity baseEntity =new BaseEntity();
        houseDetailService.importPriceList(uploadFile,request);
        baseEntity.setInfoCode(code);
        baseEntity.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return  JSON.toJSONString(baseEntity);
    }


    //一



    /*@ResponseBody
    @RequestMapping(value = "/importCustomerList",method = RequestMethod.POST)
    private String importCustomerList(@RequestParam("file") MultipartFile file,HttpServletRequest request) {
        if (file == null) {
            //判断文件大小
            return "上传文件为空文档";
        }
        Integer code = -1;
        BaseEntity baseEntity =new BaseEntity();
        customerService.importCustomerList(file);
        baseEntity.setInfoCode(code);
        baseEntity.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return  JSON.toJSONString(baseEntity);
    }*/

    /**
     * 在售房源信息列表
     * @param entity
     * @param request
     * @return
     */
    @RequestMapping(value = "/showOnSaleHouseList")
    private String showOnSaleHouseList(HouseEntity entity, HttpServletRequest request) {
        List<HouseDetail> houseDetailList = houseDetailService.showOnSaleHouseList();
        return JSON.toJSONString(houseDetailList);
    }

    /**
     * 下达下月任务
     * @param userTask
     * @param request
     * @return
     */
    @RequestMapping(value = "/nextMonthTask")
    private String nextMonthTask(UserTask userTask,HttpServletRequest request){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        try {
            calendar.setTime(sdf.parse(sdf.format(new Date())));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        calendar.add(Calendar.MONTH, 1);
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        Integer code = -1;
        BaseEntity baseEntity =new BaseEntity();
        //正式任务判断
        if (userTask.getTaskType() == 0) {
            //判断是否已经下达下月任务信息
            synchronized (this) {
                if (userTaskService.yz(sdf.format(calendar.getTime())) > 0) {
                    code = -4399;
                    baseEntity.setInfoCode(code);
                    baseEntity.setInfoText(SysExecRsUtil.getMsgFromCode(code));
                    return JSON.toJSONString(baseEntity);
                }
            }
        }
        //防止id没有被前端清空
        userTask.setId(null);
        userTask.setDistributionUserId(userService.findByTelePhone(request.getSession().getAttribute("user").toString()).getId().toString());
        if (userTask.getDealNum() == null){
            userTask.setDealNum("0");
        }
        if (userTask.getExpandCustomerNum() == null){
            userTask.setExpandCustomerNum("0");
        }
        if (userTask.getInvitationNum() == null){
            userTask.setInvitationNum("0");
        }
        if (userTask.getIsShow() == null){
            userTask.setIsShow(0);
        }
        if (userTask.getTaskType() == 0){
            userTask.setEndTime(sdf.format(calendar.getTime()));
        }
        if (userTaskService.insert(userTask) > 0){
            code = 1;
        }
        baseEntity.setInfoCode(code);
        baseEntity.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return JSON.toJSONString(baseEntity);
    }


    //导入客户基本信息
    @ResponseBody
    @RequestMapping(value = "/importCustomerList",method = RequestMethod.POST)
    private String importCustomerList(@RequestParam("file") MultipartFile uploadFile,HttpServletRequest request) {
        if (uploadFile == null) {
            //判断文件大小
            return "上传文件为空文档";
        }
        Integer code = 1;
        BaseEntity baseEntity =new BaseEntity();
        customerService.importCustomerList(uploadFile,request);
        baseEntity.setInfoCode(code);
        baseEntity.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return  JSON.toJSONString(baseEntity);
    }



}
